import { createApp } from "vue";
import Antd from "ant-design-vue";
import "ant-design-vue/dist/reset.css";
import App from "./App.vue";
import router from "@/router";
import { createPinia } from "pinia";
import "@/assets/style/common.css";
import { setupPermissionGuard } from "@/router/guard";

const pinia = createPinia();

/**
 * ==================================引入阿里图标库==================================
 */
// 引入全局可用阿里图标样式文件
import "@/assets/iconfont/iconfont.css";
// 引入全局可用阿里图标js文件
import "@/assets/iconfont/iconfont.js";

// 创建应用实例
const app = createApp(App);
const baseApiUrl = import.meta.env.VITE_GLOB_DOMAIN_URL;

window._CONFIG["_projectPath"] = import.meta.env.VITE_PUBLIC_PATH;

// 全局方法
app.config.globalProperties.getFile = (fileUrl, prefix = "http") => {
  let result = fileUrl;
  try {
    if (fileUrl && fileUrl.length > 0 && !fileUrl.startsWith(prefix)) {
      //判断是否是数组格式
      let isArray = fileUrl.indexOf("[") !== -1;
      if (!isArray) {
        let prefix = `${baseApiUrl}/common/static/`;
        // 判断是否已包含前缀
        if (!fileUrl.startsWith(prefix)) {
          result = `${prefix}${fileUrl}`;
        }
      }
    }
  } catch (err) {
  }
  return result;
};

app.use(router); // 引用路由实例
app.use(pinia);

// 路由保护
setupPermissionGuard(router);

app.use(Antd);

// 挂载应用
app.mount("#app");
